// useLoginModal.js

import { getCurrentInstance } from 'vue'

export function useLoginModal () {
  const { proxy } = getCurrentInstance()
  const loginModal = proxy.$refs.loginModal

  function openLoginModal (func) {
    if (uni.getStorageSync('token')) {
      func()
    } else {
      proxy.$refs.loginModal.popupOpen(func)
    }
  }

  function closeLoginModal () {
    proxy.$refs.loginModal.$refs.popup.close()
  }

  return {
    loginModal,
    openLoginModal,
    closeLoginModal
  }
}
